home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-19 | 2.7 KB | 65 lines | [TEXT/CWIE] |
- (*
- Problem 09 - State Machine
-
- type GetNextCharProc = function( curstate: UInt32 ): UInt32;
-
- procedure StateMachineInit( var state_machine: Handle; states: UInt32; chars:
- UInt32 );
- procedure AddTransition( state_machine: Handle; state1, state2: UInt32;
- first_char, last_char: UInt32 );
- procedure RunStateMachine( state_machine: Handle; start_state: UInt32;
- GetNextChar: GetNextCharProc; var stop_state: UInt32 );
-
- This problem requires you to maintain and operate a state machine, consisting
- of rules that change the current machine state based on the current input. Our
- state machines do not require that you produce any output other than the
- machine state.
-
- StateMachineInit creates a new, empty state machine ready to accept state
- transitions, and containing states states (numbers 1 to states) and chars
- characters (numbered 1 to chars). All the state machine information must be
- stored in the real Mac memory manager handle - it will be disposed with
- DisposeHandle and that must release all memory, so dont store any extra
- information outside the handle. Also, you must be able to deal with having
- multiple state machine instantiated simultaneously.
-
- AddTransition adds a transition from state1 to state2 for characters between
- (inclusive) first_char and last_char. When you get to state1 and get a
- character between first_char and last_char you should proceed to state2. The
- new transition overrides and previous transitions for these characters from
- state1 (ie, if you get transition 1->2 for chars 1-10, and then 1->3 for chars
- 5-6, you now have transition 1->2 for chars 1-4 and 7-10 and transition 1->3
- for chars 5-6).
-
- RunStateMachine starts in start_state and calls GetNextChar repeatedly until
- either it returns 0 or until it returns a character for which there is no
- transition at the current state. Each time GerNewChar supplies a character,
- the current state is updated based on the transition rule that applies to that
- combination of current state and current input. When GetNextChar supplies a
- state for which no transition rule exists, the state machine halts and the
- final state is returned in stop_state.
- *)
-
- unit Solution;
-
- interface
-
- // Do not modify the interface
-
- uses
- Types, Files;
-
- type GetNextCharProc = function( state_machine: Handle): UInt32;
-
- procedure StateMachineInit( var state_machine: Handle; states: UInt32; chars: UInt32 );
- procedure AddTransition( state_machine: Handle; state1, state2: UInt32; first_char, last_char: UInt32 );
- procedure RunStateMachine( state_machine: Handle; start_state: UInt32; GetNextChar: GetNextCharProc; var stop_state: UInt32 );
-
- implementation
-
- // Fill in your solution and then submit this folder
-
- // Team Name: FILL IN YOUR TEAM NAME!
-
- end.
-